package com.mxpio.erp.plm.controller;

import com.mxpio.erp.common.enums.CommonEnums;
import com.mxpio.erp.common.plm.entity.ProjectTaskDeliverable;
import com.mxpio.erp.common.plm.entity.ProjectTaskDeliverableDraft;
import com.mxpio.erp.common.plm.service.ProjectTaskDeliverableDraftService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Operator;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Tag(name = "ProjectTaskDeliverableDraftController", description = "任务-交付物-草稿表")
@RestController
@RequestMapping("/erp/plm/pro/tasks/deliverables/draft/")
public class ProjectTaskDeliverableDraftController {

    @Autowired
    private ProjectTaskDeliverableDraftService projectTaskDeliverableDraftService;
    @GetMapping("list/{taskLogId}")
    @Operation(summary = "根据任务编码获取交付物列表", description = "根据任务编码获取交付物列表（无分页）", method = "GET")
    public Result<List<ProjectTaskDeliverableDraft>> listByTaskCode(@PathVariable(name = "taskLogId", required = true) String taskLogId) {
        ArrayList<ProjectTaskDeliverableDraft> projectTaskDeliverableDrafts = new ArrayList<>();
        Criteria criteria = Criteria.create().addCriterion("taskLogId", Operator.EQ, taskLogId);
        List<ProjectTaskDeliverableDraft> list = projectTaskDeliverableDraftService.list(ProjectTaskDeliverableDraft.class, criteria);
//        for (ProjectTaskDeliverableDraft draft : list){
//            if (draft.getIsAuditEnd()==null||draft.getIsAuditEnd().equals(CommonEnums.YesNo.NO.getCode())){
//                projectTaskDeliverableDrafts.add(draft);
//            }
//        }
        return Result.OK(list);
    }
}
